package com.wc.alorithm_blue_bridge._数学知识.质数.转为质数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/8 16:41
 * @description
 * 暴力双指针
 * https://www.lanqiao.cn/problems/8113/learning/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static boolean[] st = new boolean[N];
    static int[] primes = new int[N];
    static int n, cnt = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        int plen = String.valueOf(n).length();
        ola(n);
        int res = -1;
        for (int i = cnt; i >= 1; i--) {
            int x = primes[i], y = n;
            int len = String.valueOf(x).length();
            while (x > 0 && y > 0) {
                if (x % 10 == y % 10) x /= 10;
                y /= 10;
            }
            if (x == 0) {
                res =  plen - len;
                break;
            }
        }
        out.println(res == -1 ? "No Sive!" : res);
        out.flush();
    }

    static void ola(int n) {
        st[0] = st[1] = true;
        for (int i = 2; i <= n; i++) {
            if (!st[i]) primes[++cnt] = i;
            for (int j = 1; primes[j] <= n / i; j++) {
                st[i * primes[j]] = true;
                if (i % primes[j] == 0) break;
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

